package com.youle.askdao.sys;

import com.youle.askdao.common.result.Result;
import com.youle.askdao.common.result.ResultException;
import com.youle.askdao.common.result.ResultUtil;
import com.youle.askdao.entity.bean.User;
import com.youle.askdao.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(description = "登陆-注册控制器")
@RestController
@RequestMapping("login")
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation(value = "获得用户列表", httpMethod = "POST", produces = "application/json",
            response = Result.class, notes = "获得用户列表")
    @PostMapping(value = "getUsers")
    public Result getUsers() {
        try {
            List<User> users = userService.selectAll();
            return ResultUtil.success(users);
        } catch (ResultException e) {
            e.printStackTrace();
            return ResultUtil.error(e.getErrorCode(), e.getMessage());
        }

    }

}
